Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
The 'caller' npm package is used to identify the calling function or module in a Node.js application. It helps in debugging, logging, and tracing the flow of execution by providing information about the caller of a function.
Get the calling function
This feature allows you to get the file path of the calling function. In the example, 'caller()' is used inside 'exampleFunction' to log the file path of 'anotherFunction' which called 'exampleFunction'.
const caller = require('caller');
function exampleFunction() {
console.log('Caller:', caller());
}
function anotherFunction() {
exampleFunction();
}
anotherFunction();
Get the calling module
This feature allows you to get the file path of the calling module. In the example, 'caller()' is used inside 'exampleFunction' to log the file path of the module that required 'exampleFunction'.
const caller = require('caller');
module.exports = function exampleFunction() {
console.log('Caller module:', caller());
};
const exampleFunction = require('./exampleFunction');
exampleFunction();
The 'callsite' package provides a way to get detailed information about the call stack, including file paths, line numbers, and function names. It offers more detailed stack trace information compared to 'caller', which focuses on the immediate caller.
The 'stack-trace' package allows you to capture and manipulate stack traces in Node.js. It provides more comprehensive stack trace information and is useful for advanced debugging and error handling, whereas 'caller' is more lightweight and focused on identifying the immediate caller.
Figure out your caller (thanks to @substack).
// foo.js
var bar = require('bar');
// bar.js
var caller = require('caller');
console.log(caller()); // `/path/to/foo.js`
// foo.js
var bar = require('bar');
bar.doWork();
// bar.js
var caller = require('caller');
exports.doWork = function () {
console.log(caller()); // `/path/to/foo.js`
};
Caller also accepts a depth
argument for tracing back further (defaults to 1
).
// foo.js
var bar = require('bar');
bar.doWork();
// bar.js
var baz = require('baz');
exports.doWork = function () {
baz.doWork();
};
// baz.js
var caller = require('caller');
exports.doWork = function () {
console.log(caller(2)); // `/path/to/foo.js`
};
v1.1.0 (March 9, 2022)
FAQs
@substack's caller.js as a module
The npm package caller receives a total of 157,065 weekly downloads. As such, caller popularity was classified as popular.
We found that caller demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.